
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/10/2012 14:57:45
-- Generated from EDMX file: B:\Projects\VS2010\diabetes.watb.nl\Datamodel.Diabetes\Diabetes.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Diabetes];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'BaseClassSet'
CREATE TABLE [dbo].[BaseClassSet] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'BaseClassSet_Medication'
CREATE TABLE [dbo].[BaseClassSet_Medication] (
    [Name] nvarchar(64)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'BaseClassSet_Dosage'
CREATE TABLE [dbo].[BaseClassSet_Dosage] (
    [Amount] int  NULL,
    [Motivation] nvarchar(max)  NULL,
    [Id] int  NOT NULL,
    [Medication_Id] int  NOT NULL,
    [Moment_Id] int  NOT NULL
);
GO

-- Creating table 'BaseClassSet_Moment'
CREATE TABLE [dbo].[BaseClassSet_Moment] (
    [Name] nvarchar(20)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'BaseClassSet_MedicationMoment'
CREATE TABLE [dbo].[BaseClassSet_MedicationMoment] (
    [Id] int  NOT NULL
);
GO

-- Creating table 'BaseClassSet_Day'
CREATE TABLE [dbo].[BaseClassSet_Day] (
    [Date] datetime  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'BaseClassSet_TakenMedication'
CREATE TABLE [dbo].[BaseClassSet_TakenMedication] (
    [Amount] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL,
    [Date_Id] int  NOT NULL,
    [Dosage_Id] int  NOT NULL
);
GO

-- Creating table 'BaseClassSet_MeasurementMoment'
CREATE TABLE [dbo].[BaseClassSet_MeasurementMoment] (
    [Id] int  NOT NULL
);
GO

-- Creating table 'BaseClassSet_Measurement'
CREATE TABLE [dbo].[BaseClassSet_Measurement] (
    [Result] int  NOT NULL,
    [Time] datetime  NULL,
    [Motivation] nvarchar(max)  NULL,
    [Id] int  NOT NULL,
    [MeasurementMoment_Id] int  NOT NULL,
    [Day_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'BaseClassSet'
ALTER TABLE [dbo].[BaseClassSet]
ADD CONSTRAINT [PK_BaseClassSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseClassSet_Medication'
ALTER TABLE [dbo].[BaseClassSet_Medication]
ADD CONSTRAINT [PK_BaseClassSet_Medication]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseClassSet_Dosage'
ALTER TABLE [dbo].[BaseClassSet_Dosage]
ADD CONSTRAINT [PK_BaseClassSet_Dosage]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseClassSet_Moment'
ALTER TABLE [dbo].[BaseClassSet_Moment]
ADD CONSTRAINT [PK_BaseClassSet_Moment]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseClassSet_MedicationMoment'
ALTER TABLE [dbo].[BaseClassSet_MedicationMoment]
ADD CONSTRAINT [PK_BaseClassSet_MedicationMoment]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseClassSet_Day'
ALTER TABLE [dbo].[BaseClassSet_Day]
ADD CONSTRAINT [PK_BaseClassSet_Day]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseClassSet_TakenMedication'
ALTER TABLE [dbo].[BaseClassSet_TakenMedication]
ADD CONSTRAINT [PK_BaseClassSet_TakenMedication]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseClassSet_MeasurementMoment'
ALTER TABLE [dbo].[BaseClassSet_MeasurementMoment]
ADD CONSTRAINT [PK_BaseClassSet_MeasurementMoment]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseClassSet_Measurement'
ALTER TABLE [dbo].[BaseClassSet_Measurement]
ADD CONSTRAINT [PK_BaseClassSet_Measurement]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Medication_Id] in table 'BaseClassSet_Dosage'
ALTER TABLE [dbo].[BaseClassSet_Dosage]
ADD CONSTRAINT [FK_MedicineDosages]
    FOREIGN KEY ([Medication_Id])
    REFERENCES [dbo].[BaseClassSet_Medication]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MedicineDosages'
CREATE INDEX [IX_FK_MedicineDosages]
ON [dbo].[BaseClassSet_Dosage]
    ([Medication_Id]);
GO

-- Creating foreign key on [Moment_Id] in table 'BaseClassSet_Dosage'
ALTER TABLE [dbo].[BaseClassSet_Dosage]
ADD CONSTRAINT [FK_MedicationMomentDosage]
    FOREIGN KEY ([Moment_Id])
    REFERENCES [dbo].[BaseClassSet_MedicationMoment]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MedicationMomentDosage'
CREATE INDEX [IX_FK_MedicationMomentDosage]
ON [dbo].[BaseClassSet_Dosage]
    ([Moment_Id]);
GO

-- Creating foreign key on [Date_Id] in table 'BaseClassSet_TakenMedication'
ALTER TABLE [dbo].[BaseClassSet_TakenMedication]
ADD CONSTRAINT [FK_DateTakenMedication]
    FOREIGN KEY ([Date_Id])
    REFERENCES [dbo].[BaseClassSet_Day]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DateTakenMedication'
CREATE INDEX [IX_FK_DateTakenMedication]
ON [dbo].[BaseClassSet_TakenMedication]
    ([Date_Id]);
GO

-- Creating foreign key on [MeasurementMoment_Id] in table 'BaseClassSet_Measurement'
ALTER TABLE [dbo].[BaseClassSet_Measurement]
ADD CONSTRAINT [FK_MeasurementMomentMeasurement]
    FOREIGN KEY ([MeasurementMoment_Id])
    REFERENCES [dbo].[BaseClassSet_MeasurementMoment]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MeasurementMomentMeasurement'
CREATE INDEX [IX_FK_MeasurementMomentMeasurement]
ON [dbo].[BaseClassSet_Measurement]
    ([MeasurementMoment_Id]);
GO

-- Creating foreign key on [Day_Id] in table 'BaseClassSet_Measurement'
ALTER TABLE [dbo].[BaseClassSet_Measurement]
ADD CONSTRAINT [FK_DayMeasurement]
    FOREIGN KEY ([Day_Id])
    REFERENCES [dbo].[BaseClassSet_Day]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DayMeasurement'
CREATE INDEX [IX_FK_DayMeasurement]
ON [dbo].[BaseClassSet_Measurement]
    ([Day_Id]);
GO

-- Creating foreign key on [Dosage_Id] in table 'BaseClassSet_TakenMedication'
ALTER TABLE [dbo].[BaseClassSet_TakenMedication]
ADD CONSTRAINT [FK_DosageTakenMedication]
    FOREIGN KEY ([Dosage_Id])
    REFERENCES [dbo].[BaseClassSet_Dosage]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DosageTakenMedication'
CREATE INDEX [IX_FK_DosageTakenMedication]
ON [dbo].[BaseClassSet_TakenMedication]
    ([Dosage_Id]);
GO

-- Creating foreign key on [Id] in table 'BaseClassSet_Medication'
ALTER TABLE [dbo].[BaseClassSet_Medication]
ADD CONSTRAINT [FK_Medication_inherits_BaseClass]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseClassSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseClassSet_Dosage'
ALTER TABLE [dbo].[BaseClassSet_Dosage]
ADD CONSTRAINT [FK_Dosage_inherits_BaseClass]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseClassSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseClassSet_Moment'
ALTER TABLE [dbo].[BaseClassSet_Moment]
ADD CONSTRAINT [FK_Moment_inherits_BaseClass]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseClassSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseClassSet_MedicationMoment'
ALTER TABLE [dbo].[BaseClassSet_MedicationMoment]
ADD CONSTRAINT [FK_MedicationMoment_inherits_Moment]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseClassSet_Moment]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseClassSet_Day'
ALTER TABLE [dbo].[BaseClassSet_Day]
ADD CONSTRAINT [FK_Day_inherits_BaseClass]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseClassSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseClassSet_TakenMedication'
ALTER TABLE [dbo].[BaseClassSet_TakenMedication]
ADD CONSTRAINT [FK_TakenMedication_inherits_BaseClass]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseClassSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseClassSet_MeasurementMoment'
ALTER TABLE [dbo].[BaseClassSet_MeasurementMoment]
ADD CONSTRAINT [FK_MeasurementMoment_inherits_Moment]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseClassSet_Moment]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseClassSet_Measurement'
ALTER TABLE [dbo].[BaseClassSet_Measurement]
ADD CONSTRAINT [FK_Measurement_inherits_BaseClass]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseClassSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------